Google Kubernetes Engine (GKE) is a managed Kubernetes service that simplifies the deployment, management, and scaling of containerized applications using Kubernetes. Here's a basic example of setting up Google Kubernetes Engine:
Features:
-
Managed Kubernetes:
- GKE provides a fully managed Kubernetes environment, handling tasks such as cluster orchestration, node provisioning, and health monitoring.
- Scalability:
- Easily scale your applications by adjusting the number of nodes in your GKE cluster based on demand.
- Automated Updates:
- GKE performs automatic updates to keep your cluster's Kubernetes version up-to-date.
- Integrated with Google Cloud Services:
- GKE integrates with other Google Cloud services, allowing seamless use of resources like Cloud Storage, Cloud SQL, and more.
- Multi-Cluster Management:
- You can manage multiple GKE clusters from a single interface using Google Cloud Console or the gcloud command-line tool.
Configuration Example:
Here's a basic example of setting up Google Kubernetes Engine:
-
Create a GKE Cluster:
- Use the Google Cloud Console or gcloud command-line tool to create a GKE cluster.
gcloud container clusters create my-cluster \
--num-nodes=3 \
--zone=us-central1-a
-
This command creates a GKE cluster named "my-cluster" with three nodes in the "us-central1-a" zone.
-
Get Cluster Credentials:
- After creating the cluster, fetch the cluster credentials to configure kubectl.
gcloud container clusters get-credentials my-cluster --zone=us-central1-a
Deploy an Application:
- Deploy a sample application using a Kubernetes Deployment and Service.
# my-app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app-container
image: gcr.io/google-samples/kubernetes-bootcamp:v1
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
Apply the configuration:
kubectl apply -f my-app.yaml
Expose the Application:
- Expose the application to the internet using the LoadBalancer service.
kubectl expose deployment my-app --type=LoadBalancer --port=80 --target-port=8080
Wait for the external IP to be assigned:
kubectl get service my-app-service --watch
Access the Application:
- Once the external IP is assigned, access the application in a web browser or using curl.
curl http://EXTERNAL_IP
Scale the Application:
- Scale the application by adjusting the number of replicas.
kubectl scale deployment my-app --replicas=5
Clean Up (Optional):
- If needed, delete the GKE cluster and associated resources.
gcloud container clusters delete my-cluster --zone=us-central1-a